package com.edu.lawdoc.api.utils;

import java.lang.reflect.Method;

public class EnumKit {

    public static boolean contains(Class<?> clazz, String code, String methodName) {

        if(clazz.isEnum()){
            Object[] enumConstants = clazz.getEnumConstants();
            try {
                Method getCode = clazz.getMethod(methodName);
                for (Object enumConstant:enumConstants){
                    if (getCode.invoke(enumConstant).equals(code)) {
                        return true;
                    }
                }
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        }
        return false;
    }
}
